/**
 * @author LKQ
 * @date 2022/3/1 15:19
 * @description 深度优先遍历
 */
public class Solution {
    public static void main(String[] args) {

    }
    int sum = 0;
    public int findTilt(TreeNode root) {
        dfs(root);
        return sum;
    }
    public int dfs(TreeNode node) {
        if(node == null) {
            return 0;
        }

        int left = dfs(node.left);
        int right = dfs(node.right);
        sum += Math.abs(left - right);
        return left + right + node.val;
    }
}
